//package com.example.ping.logging;
//
//import ch.qos.logback.core.AppenderBase;
//
///**
// * @author Jim
// * @create 2025/1/13
// */
//
//import com.mongodb.client.MongoClients;
//import com.mongodb.client.MongoCollection;
//import org.bson.Document;
//
//public class MongoDbAppender extends AppenderBase {
//    private String uri = "mongodb://localhost:27017"; // MongoDB URI
//    private String databaseName = "logging";
//    private String collectionName = "logs";
//
//    private MongoCollection<Document> collection;
//
//    @Override
//    public void start() {
//        // Initialize MongoDB client and collection
//        var client = MongoClients.create(uri);
//        var database = client.getDatabase(databaseName);
//        collection = database.getCollection(collectionName);
//        super.start();
//    }
//
//    @Override
//    protected void append(Object eventObject) {
//        if (eventObject instanceof ch.qos.logback.classic.spi.ILoggingEvent) {
//            var event = (ch.qos.logback.classic.spi.ILoggingEvent) eventObject;
//            var logDocument = new Document();
//            logDocument.put("timestamp", event.getTimeStamp());
//            logDocument.put("level", event.getLevel().toString());
//            logDocument.put("logger", event.getLoggerName());
//            logDocument.put("message", event.getFormattedMessage());
//
//            // Insert the log document into MongoDB
//            collection.insertOne(logDocument);
//        }
//    }
//
//    public void setUri(String uri) {
//        this.uri = uri;
//    }
//
//    public void setDatabaseName(String databaseName) {
//        this.databaseName = databaseName;
//    }
//
//    public void setCollectionName(String collectionName) {
//        this.collectionName = collectionName;
//    }
//}
